﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sharp.Migrations;

namespace Budgeter.Migrations
{
    class _006_Create_Table_Entry : SchemaMigration
    {

        public override void Up()
        {
            Add.Table("Entry").WithColumns(
                Column.AutoIncrement("EntryId").AsPrimaryKey(),
                Column.Decimal("Amount").NotNull(),
                Column.Int32("BudgetId").NotNull(),
                Column.Int32("EntryTypeId").NotNull(),
                Column.Int32("IntervalId").NotNull()
            );

            Add.ForeignKey("FK_Budget_Entry")
               .OnColumn("BudgetId")
               .OfTable("Entry")
               .ReferencingColumn("BudgetId")
               .OfTable("Budget")
               .OnDeleteNoAction();

            Add.ForeignKey("FK_EntryType_Entry")
               .OnColumn("EntryTypeId")
               .OfTable("Entry")
               .ReferencingColumn("EntryTypeId")
               .OfTable("EntryType")
               .OnDeleteNoAction();

            Add.ForeignKey("FK_Interval_Entry")
               .OnColumn("IntervalId")
               .OfTable("Entry")
               .ReferencingColumn("IntervalId")
               .OfTable("Interval")
               .OnDeleteNoAction();
        }

        public override void Down()
        {
            Remove.ForeignKey("FK_Interval_Entry").FromTable("Entry");
            Remove.ForeignKey("FK_EntryType_Entry").FromTable("Entry");
            Remove.ForeignKey("FK_Budget_Entry").FromTable("Entry");

            Remove.Table("Entry");
        }
    }
}
